package com.itheima.web.controller;

import com.itheima.domain.db.UserInfo;
import com.itheima.vo.MovementVo;
import com.itheima.vo.PageBeanVo;
import com.itheima.web.manager.UserManager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;


    //查询用户列表
    @GetMapping("/manage/users")
    public PageBeanVo findUserList(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {

        return userManager.findUserList(pageNum, pageSize);
    }


    //查询用户详情
    @GetMapping("/manage/users/{userID}")
    public UserInfo findUserInfo(@PathVariable("userID") Long userId){
        return userManager.findUserInfo(userId);
    }


    //用户视频
    @GetMapping("/manage/videos")
    public PageBeanVo findUserVideoList(Long uid,
                                        @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize
    ) {
        return userManager.findUserVideoList(uid, pageNum, pageSize);
    }


    //查询动态
    @GetMapping("/manage/messages")
    public PageBeanVo findMovementList(
            Long uid, String state,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {
        Integer stateInt = null;
        if (StringUtils.isNotEmpty(state) && !"''".equals(state)) {
            stateInt = Integer.parseInt(state);
        }

        return userManager.findMovementList(uid, stateInt, pageNum, pageSize);
    }


    //动态详情
    @GetMapping("/manage/messages/{id}")
    public MovementVo findMovementById(@PathVariable("id") String movementId) {
        return userManager.findMovementById(movementId);
    }


    //动态评论列表
    @GetMapping("/manage/messages/comments")
    public PageBeanVo findMovementComment(
            String messageID,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {
        return userManager.findMovementComment(messageID, pageNum, pageSize);
    }

    //消息通过
    @PostMapping("/manage/messages/pass")
    public String messagesPass(@RequestBody String[] str) {
        for (String s : str) {

            System.out.println(s);
        }
        userManager.messagesPass(str);
        return "OK";
    }

    //消息拒绝
    @PostMapping("/manage/messages/reject")
    public void messagesReject(@RequestBody String[] str) {
        userManager.messagesReject(str);
    }
}